package com.fromfuture.xuhuidoc.android.activity.mainframe;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.fromfuture.xuhuidoc.R;
import com.fromfuture.xuhuidoc.android.activity.LoginActivity;
import com.fromfuture.xuhuidoc.android.activity.MyConsultRoomActivity;
import com.fromfuture.xuhuidoc.android.activity.MyYuYueActivity;
import com.fromfuture.xuhuidoc.android.base.AppManager;
import com.fromfuture.xuhuidoc.android.base.BaseFragment;
import com.fromfuture.xuhuidoc.android.base.BaseWebActivity;
import com.fromfuture.xuhuidoc.android.base.MyWebview;

import java.util.ArrayList;
import java.util.List;

import app.auto.runner.base.intf.FunCallback;
import app.auto.runner.base.utility.base.Toastial;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by hp on 2017/8/17.
 */

public class WorkBenchFragment extends BaseFragment {

    @BindView(R.id.workbench_banner)
    ConvenientBanner workbench_banner;
    @BindView(R.id.workbench_lunbo_dot00_white)
    ImageView lunbo_dot00_white;
    @BindView(R.id.workbench_lunbo_dot00_grey)
    ImageView lunbo_dot00_grey;
    @BindView(R.id.workbench_lunbo_dot01_white)
    ImageView lunbo_dot01_white;
    @BindView(R.id.workbench_lunbo_dot01_grey)
    ImageView lunbo_dot01_grey;
    private View rootview;
    private MyWebview webview;
    private String tag = "WorkBenchFragment -->";
    private Unbinder unbinder;
    MainFrameActivity mainFrameActivity;
    // 视图集合
    private List imagelist_lunbo;

    public WorkBenchFragment() {
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.e(tag, "onCreateView");
        rootview = inflater.inflate(R.layout.fragment_work_bench, container, false);
        unbinder = ButterKnife.bind(this, rootview);
        mainFrameActivity = (MainFrameActivity) getActivity();
        init();
        return rootview;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }

    private void init() {
        initLunbo();
    }
//MySharedPreferencesUtils.putValue(myActivity,"DOCINFO","DOCNAME",name);

    /**
     * 咨询服务
     */
    @OnClick(R.id.workbench_consult_service)
    void workbench_consult_service() {
        LoginActivity.checkLogin(getActivity(), new FunCallback() {
            @Override
            public void simpleRun(Object aty) {
                startActivityForResult(new Intent(getActivity(), MyConsultRoomActivity.class), 01);
            }
        });
    }

    /**
     * 多人会诊
     */
    @OnClick(R.id.workbench_persons_huizhen)
    void workbench_persons_huizhen() {
        Toastial.quick("敬请期待...");
//        Intent intent = new Intent(getActivity(), BaseWebActivity.class);
//        intent.putExtra("type", AppManager.type_multiple_inquire);
//        startActivityForResult(intent, 02);
    }

    /**
     * 我的预约
     */
    @OnClick(R.id.workbench_myYuYue)
    void workbench_myYuYue() {
        Intent intent = new Intent(getActivity(), MyYuYueActivity.class);
        intent.putExtra("type", "我的预约");
        startActivityForResult(intent, 03);
    }

    /**
     * 咨询记录
     */
    @OnClick(R.id.workbench_consult_recode)
    void workbench_consult_recode() {
        Intent intent = new Intent(getActivity(), BaseWebActivity.class);
        intent.putExtra("type", AppManager.type_inquiry_record);
        startActivityForResult(intent, 04);
    }

    /**
     * 业绩考核
     */
    @OnClick(R.id.workbench_yeji_assess)
    void workbench_yeji_assess() {
        Intent intent = new Intent(getActivity(), BaseWebActivity.class);
        intent.putExtra("type", AppManager.type_yeji_assessment);
        startActivityForResult(intent, 05);
    }

    /**
     * 模板管理
     */
    @OnClick(R.id.workbench_template_manage)
    void workbench_template_manage() {
        Intent intent = new Intent(getActivity(), MyYuYueActivity.class);
        intent.putExtra("type", "模板管理");
        startActivityForResult(intent, 06);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    /**
     * 初始化滚动轮播
     */
    private void initLunbo() {
        imagelist_lunbo = new ArrayList();
        imagelist_lunbo.add(R.mipmap.banner_01);
        imagelist_lunbo.add(R.mipmap.banner_02);
        //自定义你的Holder，实现更多复杂的界面，不一定是图片翻页，其他任何控件翻页亦可。
        workbench_banner.setPages(
                new CBViewHolderCreator<LocalImageHolderView>() {
                    @Override
                    public LocalImageHolderView createHolder() {
                        return new LocalImageHolderView();
                    }
                }, imagelist_lunbo)
                .startTurning(3000)
                //设置指示器的方向
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
                .setScrollDuration(500);
        workbench_banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                try {
                    switch (position) {
                        case 0:
                            lunbo_dot00_white.setVisibility(View.VISIBLE);
                            lunbo_dot00_grey.setVisibility(View.INVISIBLE);
                            lunbo_dot01_white.setVisibility(View.INVISIBLE);
                            lunbo_dot01_grey.setVisibility(View.VISIBLE);
                            break;
                        case 1:
                            lunbo_dot00_white.setVisibility(View.INVISIBLE);
                            lunbo_dot00_grey.setVisibility(View.VISIBLE);
                            lunbo_dot01_white.setVisibility(View.VISIBLE);
                            lunbo_dot01_grey.setVisibility(View.INVISIBLE);
                            break;
                    }
                } catch (Exception e) {

                }


            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    //本地图片 用于滚动轮播
    public class LocalImageHolderView implements Holder<Integer> {
        private ImageView imageView;

        @Override
        public View createView(Context context) {
            imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            return imageView;
        }

        @Override
        public void UpdateUI(Context context, int position, Integer data) {
            imageView.setImageResource(data);
        }
    }

}
